//<ReplasablePackageBlock>
package com.slicktechnologies.client.utility;
import java.util.Vector;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Label;
import com.simplesoftwares.client.library.appskeleton.AppMemory;
import com.simplesoftwares.client.library.appskeleton.MenuItems;
import com.simplesoftwares.client.library.appskeleton.SideBarItems;
import com.slicktechnologies.client.userconfigurations.UserConfiguration;
import com.slicktechnologies.client.views.home.HomePresenter;

/**
 * The AppConnector template.
 * @author Kamala
 *
 */
public class AppConnector extends AppMemory 
{
	/**
	 * This static part runs at entry point i.e @ onModuleLoad().
	 * Creates appconnector object at runtime itself.
	 */
	private AppConnector()
	{

	}
	static{
		if(memory==null)
			memory=new AppConnector();
	}

	public static void initalizes()
	{

	}



	/**
	 * Method template to create {@link MenuItems} to be displayed on NavigationBar.
	 * @return navigationBarItems
	 */
	@Override
	public Vector<MenuItems> createNavigationBar() 
	{
		//handle navigationbar
		Vector<MenuItems> navigationBarItems=new Vector<MenuItems>();

		//Token to add menuitems in navigationBarItems
		navigationBarItems.add(createAndAddMenuItems(Screen.HOME,"Dashboard","Dashboard/Home"));
		
		if(registerationPower())
		{
			navigationBarItems.add(createAndAddMenuItems(Screen.REGISTRATION, "Registration", "Registration"));
		}
		return navigationBarItems;
	}

	/**
	 * Method template to create {@link MenuItems} to be displayed on SideBar.
	 * @return sideBarNames.
	 */
	@Override
	public Vector<SideBarItems> createSideBar() 
	{

        Vector<SideBarItems> sideBarNames=new Vector<SideBarItems>();
		Vector<MenuItems> temp;
		        
		        //Token to add menuitems in SideBarItems and add this sidebaritem in sideBarNames
		//temp=new Vector<MenuItems>();
		//temp.add(createAndAddMenuItems(Screen.USERAUTHORIZATION,"User Authorization","User Authorization/User Authorization"));
		//sideBarNames.add(new SideBarItems("User Authorization",temp));
		
		//*************Sales*******************//
	temp=new Vector<MenuItems>();
	temp.add(createAndAddMenuItems(Screen.CUSTOMER,"Customer","Customer"));
	temp.add(createAndAddMenuItems(Screen.CONTRACT,"Service Card","Sales/Service Card"));
	temp.add(createAndAddMenuItems(Screen.CATEGORY,"Category","Sales/Category"));
	temp.add(createAndAddMenuItems(Screen.BRAND,"Brand","Sales/Brand"));
	temp.add(createAndAddMenuItems(Screen.CUSTOMERPARTICULARS,"Customer Particulars","Sales/Customer Particulars"));
	
	temp.add(createAndAddMenuItems(Screen.SERVICETYPE,"Service Type","Sales/Service Type"));
	sideBarNames.add(new SideBarItems("Sales",temp));

	

	
	
	
	
	
	
	
	
	
	//**************Settings********************//
	temp=new Vector<MenuItems>();
	
	
	temp.add(createAndAddMenuItems(Screen.EMPLOYEE,"Employee","Human Resource/Employee"));
	temp.add(createAndAddMenuItems(Screen.USER,"User","Settings/User"));
	temp.add(createAndAddMenuItems(Screen.BRANCH,"Branch","Settings/Branch"));
	sideBarNames.add(new SideBarItems("Settings",temp));
	
	
	
	
	//******************Account***********************//
	temp=new Vector<MenuItems>();
	temp.add(createAndAddMenuItems(Screen.EXPENSEMANAGMENT,"Expense Management","Accounts/Expense Management"));
	temp.add(createAndAddMenuItems(Screen.COMPANY,"Company","Accounts/Company"));
	
	sideBarNames.add(new SideBarItems("Accounts",temp));
	
	//*******Account Config*************//
	temp=new Vector<MenuItems>();
	temp.add(createAndAddMenuItems(Screen.EXPENSEGROUP, "Expense Group", "Account Configuration/Expense Group"));
	temp.add(createAndAddMenuItems(Screen.EXPENSECATEGORY,"Expense Category","Account Configuration/Expense Category"));
	temp.add(createAndAddMenuItems(Screen.EXPENSETYPE,"Expense Type","Account Configuration/Expense Type"));
	temp.add(createAndAddMenuItems(Screen.PAYMENTMETHODS,"Payment Method","Account Configuration/Payment Method"));
	temp.add(createAndAddMenuItems(Screen.PAYMENTTERMS,"Payment Terms","Account Configuration/Payment Terms"));
	temp.add(createAndAddMenuItems(Screen.CURRENCY,"Currency","Account Configuration/Currency"));
	temp.add(createAndAddMenuItems(Screen.COMPANYTYPE,"Company Type","Account Configuration/Company Type"));
	sideBarNames.add(new SideBarItems("Account Configuration", temp));
	
	
	
		return sideBarNames;
	}


	/**
	 * AppLevel menu names to be displayed on AppHeaderBar.
	 * @return menuNames
	 */
	@Override
	public String[] getApplevelMenus()
	{

		//Create App Level Menu
		String[]menuNames={"Save","Discard","Search","Email","Print","Edit","Download"};
		return menuNames;
	}

	/**
	 * Method template to redirect the screen to the Home page.
	 */
	@Override
	public void goToHome() {
            HomePresenter.initalize();

	}

	/**
	 * Method to create {@link MenuItems} objects.
	 * @param screen the screen
	 * @param widgettitle title of the widget
	 * @param processname title to be displayed on the AppHeaderBar.
	 * @return MenuItems
	 */
	private MenuItems  createAndAddMenuItems(Screen screen,String widgettitle,String processname)
	{
		Label lbltemp=new Label(widgettitle);
		
		
		
	
		MenuItems itemtemp=new MenuItems(lbltemp,screen,processname);

		//System.out.println("Item tnp="+isAuthorized);
		//if(isAuthorized)

		//System.out.println("Item tnp="+isAuthorized);
		//if(isAuthorized)


		{
		    items.add(itemtemp);
		    return itemtemp;
		    
		    
		}
	

		//return null;

	}
	
	
	private boolean registerationPower()
	{
		String url=Window.Location.getHref();
		System.out.println("URL-------- "+url);
		String[] spliturl=url.split("\\.");
		String companyname=spliturl[0];
		companyname=companyname.replace("http://","");
		/*if(companyname.equals("admineva"))
			return true;
		else
			return false;*/
		return true;
	}
}




